#include<bits/stdc++.h>
using namespace std;
int n,m,l,V,ans=0,nd,kk;
double gt;
int T;
int d[100100];
int v[100100];
int a[100100];
int b[100100];
bool f[1000100],p;
bool vis[100100],vis2[100100];
vector<int> g[1000100];
bool cmd(vector<int> xx,vector<int> yy){
    return xx.size()>yy.size();
}
void sov1(){
    int s=0;
    for(int i=1;i<=n;i++){
        if(v[i]>V&&d[i]<=b[n]){
            s++;
        }
    }
    cout<<s<<" "<<n-1;
}
vector<int> q;

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        ans=0;
        bool sol1=true;
        memset(d,0,sizeof(d));
        memset(v,0,sizeof(v));
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(f,0,sizeof(f));
        memset(vis,0,sizeof(vis));
        memset(vis2,0,sizeof(vis2));
        cin>>n>>m>>l>>V;
        nd=n;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]!=0)sol1=0;
        }
        for(int i=1;i<=m;i++){
            cin>>b[i];
            f[b[i]]=1;
        }
        if(sol1){
            sov1();
            continue;
        }
        for(int i=1;i<=n;i++){
            p=1;
            if(a[i]==0||(v[i]>V&&a[i]>0)){
                if(v[i]>V&&d[i]<=b[n]){
                    p=0;
                    ans++;
                    for(int j=d[i];j<=b[n];j++)
                    {
                        if(f[j]==1)g[j].push_back(i);
                    }
                }
            }
            else if(v[i]<=V&&a[i]<0){
                continue;
            }
            else if(v[i]>V&&a[i]<0){
                gt=(V*V-v[i]*v[i])*1.0/(2*a[i]);
                if(gt>l)gt=l;
                for(int j=1;j<=gt;j++){
                    if(f[j+d[i]]==1){
                        if(p)ans++;
                        p=0;
                        g[j+d[i]].push_back(i);
                    }
                }
            }
            else if(v[i]<=V&&a[i]>0){
                gt=(V*V-v[i]*v[i])*1.0/(2*a[i]);
                for(int j=ceil(gt+d[i])+1;j<=b[n];j++){
                    if(f[j]==1){
                        if(p)ans++;
                        p=0;
                        g[j].push_back(i);
                    }
                }
            }
            if(p==1)
            {
                nd=nd-1;
                //cout<<i<<endl;
            }
        }
        sort(g+1,g+1+l,cmd);
        kk=0;
        for(int i=1;i<=m;i++){
            bool kj=0;
            if(nd==0)
                break;

            for(int v:g[i]){

                if(vis[v]==0){
                    nd-=1;
                    vis[v]=1;
                    kj=1;
                }
            }

            if(kj)kk++;
            g[i].clear();
        }
        cout<<ans<<" "<<n-kk<<endl;
    }

    return 0;
}
